import {iProcessActionRender} from "react-cms-visual-editor/src/packages/createVisualEditorUser/createVisualEditorAction/createVisualEditorActionRender"
import {iVisualComponentActionData, RenderNode} from "react-cms-visual-editor/src/packages/utils/types.base"
import {NextLink} from "../components/NextLink";

/**
 * 预定义动作渲染
 * @author  韦胜健
 * @date    2022/2/6 23:37
 */
export const processActionRender: iProcessActionRender = ({registryActionRender}) => {

    registryActionRender(
        '@@fixed',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={data.data} {...attrs}>
                {content}
            </a>
        )
    )

    registryActionRender(
        'pdp',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <NextLink href={`/pdp/${data.data.id}`} key={attrs.key} attrs={attrs}>
                {content}
            </NextLink>
        ))

    registryActionRender(
        'category',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <NextLink href={`/plp?category=${data.data.id}`} key={attrs.key} attrs={attrs}>
                {content}
            </NextLink>
        ),
    )

    /*registryActionRender(
        'activity',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={`activity?category=${data.data.code}`} {...attrs} onClick={(e) => {
                openFail(e)
                !!attrs.onClick && attrs.onClick(e)
            }}>
                {content}
            </a>
        ),
    )*/
}
